package com.xdf.xzymanagementsystem.controller;

import com.xdf.xzymanagementsystem.entity.HalfMainDTO;
import com.xdf.xzymanagementsystem.entity.OrderDetail;
import com.xdf.xzymanagementsystem.entity.OrderFee;
import com.xdf.xzymanagementsystem.enums.MenuConstant;
import com.xdf.xzymanagementsystem.enums.OperateConstant;
import com.xdf.xzymanagementsystem.enums.ResponseEnum;
import com.xdf.xzymanagementsystem.enums.SeparatorConstant;
import com.xdf.xzymanagementsystem.service.OrderFeeService;
import com.xdf.xzymanagementsystem.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 注意要有依赖：
 *         <dependency>
 *             <groupId>io.springfox</groupId>
 *             <artifactId>springfox-swagger2</artifactId>
 *             <version>2.9.2</version>
 *         </dependency>
 *         <dependency>
 *             <groupId>io.springfox</groupId>
 *             <artifactId>springfox-swagger-ui</artifactId>
 *             <version>2.9.2</version>
 *         </dependency>
 * 同时入口类头上使用注解：@EnableSwagger2
 * @Description : 控制层，代码生成器自动生成
 * @Author : chanchaw
 * @Date : 2025-3-22 10:27:04
 */
@Api(tags = "单据,明细,订单")
@CrossOrigin
@RestController
@RequestMapping("/orderFee")
public class OrderFeeController {
    @Autowired
    private OrderFeeService service;
    //=================以上是自动生成的代码，自定义代码请写在下面==================

    /**
     * 新增单据
     * @param record
     * @return
     */
    @ApiOperation(value = "新增单据", httpMethod = "POST")
    @RequiresPermissions(MenuConstant.MENU203 + SeparatorConstant.SEPARATOR + OperateConstant.ADD)
    @PostMapping("/insert")
    public OrderFee insert(@RequestBody OrderFee record) throws Exception {
        return service.insert(record);
    }

    /**
     * 新增单据
     * @param record
     * @return
     */
    @ApiOperation(value = "新增单据", httpMethod = "POST")
    @RequiresPermissions(MenuConstant.MENU203 + SeparatorConstant.SEPARATOR + OperateConstant.ADD)
    @PostMapping("/update")
    public OrderFee update(@RequestBody OrderFee record) throws Exception {
        return service.update(record);
    }

    /**
     * 作废费用
     * @param id
     * @return
     */
    @ApiOperation(value = "作废费用", httpMethod = "POST")
    @RequiresPermissions(MenuConstant.MENU101 + SeparatorConstant.SEPARATOR + OperateConstant.MODIFY)
    @PostMapping("/deleteById/{id}")
    public JsonResult deleteById(@PathVariable Integer id){
        service.deleteById(id);
        return JsonResult.ok(ResponseEnum.OK.getName());
    }

    /**
     * 根据订单主表主键查询
     * @param id
     * @return
     */
    @ApiOperation(value = "根据订单主表主键查询", httpMethod = "POST")
    @RequiresPermissions(MenuConstant.MENU101 + SeparatorConstant.SEPARATOR + OperateConstant.SHOW)
    @PostMapping("/selectByMainId")
    public List<OrderFee> selectByMainId(@RequestParam("id") Integer id){
        return service.selectByMainId(id);
    }

    /**
     * 费用明细序时表
     * @param sdate
     * @param edate
     * @param flag
     * @return
     */
    @GetMapping("/selectAllByDate")
    @RequiresPermissions(MenuConstant.MENU101 + SeparatorConstant.SEPARATOR + OperateConstant.SHOW)
    public List<Map<String, Object>> selectAllByDate(@DateTimeFormat(pattern = "yyyy-MM-dd") Date sdate,
                                                  @DateTimeFormat(pattern = "yyyy-MM-dd") Date edate) {
        System.out.println("sdate:" + sdate + ",edate:" + edate);
        List<Map<String, Object>> list = service.selectAllByDate(sdate, edate);
        return list;
    }
}